package com.example.supplychainbackend.controller;

import com.example.supplychainbackend.controller.dto.DataResponse;
import com.example.supplychainbackend.controller.dto.ReviewRequestDto;
import com.example.supplychainbackend.controller.dto.supervise.*;
import com.example.supplychainbackend.entity.supervise.ComplaintEntity;
import com.example.supplychainbackend.mapper.SuperviseMapper;
import com.example.supplychainbackend.service.SuperviseService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/supervise")
@AllArgsConstructor
public class SuperviseController {
    private final SuperviseService superviseService;
    private final SuperviseMapper mapper;
    //溯源码申请信息查询
    @GetMapping("/traceApply/list")
    public DataResponse<List<TraceApplyDto>> listTraceApplys(){
        List<TraceApplyDto> res = superviseService.listTraceApplys();
        return DataResponse.success(res);
    }

    //溯源码申请信息审核、驳回
    @PutMapping("traceApply/review/{id}")
    public DataResponse<Integer> reviewTraceApply(@PathVariable String id, @RequestBody ReviewRequestDto req){
        Integer res = superviseService.reviewTraceApply(id, req.getType());
        return DataResponse.success(res);
    }

    @PostMapping("/complaint")
    public DataResponse<ComplaintDto> createComplaint(@RequestBody ComplaintDto dto){
        ComplaintEntity entity = superviseService.createComplaint(dto);
        return  DataResponse.success(mapper.toComplaintDto(entity));
    }

    @GetMapping("/complaint/list")
    public DataResponse<List<ComplaintDto>> listComplaints(){
        List<ComplaintDto> res = superviseService.listComplaints();
        return DataResponse.success(res);
    }

    @PutMapping("/complaint/review/{id}")
    public DataResponse<ComplaintDto> reviewTraceApply(@PathVariable String id){
        ComplaintDto res = superviseService.reviewComplaint(id);
        return DataResponse.success(res);
    }

    @GetMapping("/enterprise/list")
    public DataResponse<List<EnterpriseCertApplyDto>> listEnterpriseCertApplies(){
        List<EnterpriseCertApplyDto> res = superviseService.listEnterpriseCertApplies();
        return DataResponse.success(res);
    }

    @PutMapping("/enterprise/review/{id}")
    public DataResponse<Long> reviewEnterpriseCertApply(@PathVariable Long id, @RequestBody ReviewRequestDto req){
        Long res = superviseService.reviewEnterpriseCertApply(id, req.getType());
        return DataResponse.success(res);
    }

    @GetMapping("/production/list")
    public DataResponse<List<ProductionCertApplyDto>> listProductionCertApplies(){
        List<ProductionCertApplyDto> res = superviseService.listProductionCertApplies();
        return DataResponse.success(res);
    }

    @PutMapping("/production/review/{id}")
    public DataResponse<Long> reviewProductionCertApply(@PathVariable Long id, @RequestBody ReviewRequestDto req){
        Long res = superviseService.reviewProductionCertApply(id, req.getType());
        return DataResponse.success(res);
    }


}
